package com.minelx.statementplus.ui.form.dao;

import javax.swing.*;
import java.util.List;

public abstract class BaseListModel<E> extends AbstractListModel<E> {
	@Override
	public abstract int getSize();

	@Override
	public abstract E getElementAt(int index);

	protected abstract void append(E element);

	protected abstract void remove(int index);

	public abstract void removeAll();

	public abstract List<E> toList();

	public final void addElement(E element) {
		int size = getSize();
		append(element);
		fireIntervalAdded(this, size, size);
	}

	public final void removeElement(int index) {
		remove(index);
		fireIntervalRemoved(this, index, index);
	}

	public final void clear() {
		removeAll();
		fireIntervalRemoved(this, 0, getSize());
	}
}
